import type { SignInParamType } from "~/types/user";

export default () => {
    const { createHttpFetch } = useHttpRequest();
    const { setToken, clearToken } = useToken();

    const signin = async (userData: SignInParamType) => {
        const response = await createHttpFetch<{ token: string }>('/api/signin', { method: 'POST', body: userData });
        setToken(response.data.token);
        return response;
    };

    const signup = (userData: SignInParamType) => {
        return createHttpFetch('/api/signup', { method: 'POST', body: userData });
    };

    const signout = async () => {
        const response = await createHttpFetch('/api/signout', { method: 'PUT' });
        clearToken();
        return response;
    };

    return { signin, signup, signout };
};